package com.fishing.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.protocol.HTTP;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;

import QL.ButlerBankItemLogQueryRequest;
import QL.ButlerBankItemLogQueryResponse;
import QL.ButlerBankItemQueryRequest;
import QL.ButlerBankItemQueryResponse;
import QL.QLClient;

/**
 *金库系统 
 *@author lrz 
 * */

@Controller
public class TreasuryController {
    
	private static QLClient client = new QLClient();
	@RequestMapping("treasury/toList")
	public ModelAndView toList(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("treasury/list");
		return mav;
	}
	
	@ResponseBody
	@RequestMapping(value="treasury/list",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
	public Map list(HttpServletRequest request,String UserId,String LogType,String PageIndex,String PageCount) {
		ButlerBankItemLogQueryRequest req = new  ButlerBankItemLogQueryRequest();
		Map<String,Object> map = new HashMap<>();
		try {
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.UserId = UserId == ""?0:Integer.parseInt(UserId);
			req.LogType = Integer.parseInt(LogType);
			req.PageIndex = Integer.parseInt(PageIndex) -1;
			req.PageCount = Integer.parseInt(PageCount);
			ButlerBankItemLogQueryResponse rsp = new ButlerBankItemLogQueryResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if(rsp.LogList == null) {
				map.put("data", 0);
				map.put("count", 0);
				map.put("status", "200");
				map.put("message", "");
				return map;
			}else {
				map.put("data", rsp.LogList);
				map.put("count", rsp.TotalCount);
				map.put("status", "200");
				map.put("message", "");
				return map;
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("data", 0);
			map.put("count", 0);
			map.put("status", "200");
			map.put("message", "");
			return map;
		}
	}
	
	@RequestMapping("treasury/findUserId")
	public ModelAndView findUserId(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("treasury/findUserId");
		return mav;
	}
	
	@ResponseBody
	@RequestMapping(value="treasury/UserIdWoods",method=RequestMethod.POST,produces="text/html;charset=UTF-8")
	public Map UserIdWoods(HttpServletRequest request,String UserId) {
		System.out.println(UserId);
		ButlerBankItemQueryRequest req = new ButlerBankItemQueryRequest();
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		Map<String,Object> map = new HashMap<>();
		try {
			req.UserId = Integer.parseInt(UserId);
			ButlerBankItemQueryResponse rsp = new ButlerBankItemQueryResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			if(rsp.Items == null) {
				map.put("data", 0);
				map.put("count", 0);
				map.put("status", "200");
				map.put("message", "");
				return map;
			}else {
				map.put("data", rsp.Items);
				map.put("count", rsp.Items.size());
				map.put("status", "200");
				map.put("message", "");
				return map;
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("data", 0);
			map.put("count", 0);
			map.put("status", "200");
			map.put("message", "");
			return map;
		}
		
	}
}
